<?php
/**
 * CityController
 */
namespace App\Http\ControllersAdmin;

use App\Service\DicsService;
use App\Validation\CitySearchValidation;
use App\Validation\DicsSearchValidation;
use App\Validation\DeleteValidation;
use App\Validation\DicsValidation;

class CityController extends BaseController
{
	const CATE_AREA = -1;		//城市区域
	const CATE_UNIQUE = -2;		//城市特色

	/**
	 * [indexAction 城市列表]
	 * @return [type] [description]
	 */
	public function indexAction()
	{
		$raw = $this->validation(new DicsSearchValidation, $this->request->getJsonRawBody());
		$raw->type = self::CATE_AREA;
		$raw->pid  = 0;
		$data = DicsService::getSearch($raw);

		$count = DicsService::getSearch($raw, TRUE);
		$assign = [
			'total' => $count,
			'list'  => $data
		];
		return $this->echoJson($assign);
	}

	/**
	 * [uniqueAction 城市特色列表]
	 * @return [type] [description]
	 */
	public function uniqueAction()
	{
		$raw = $this->validation(new DicsSearchValidation, $this->request->getJsonRawBody());
		$raw->type = self::CATE_UNIQUE;
		$data = DicsService::getSearch($raw);

		$count = DicsService::getSearch($raw, TRUE);
		$assign = [
			'total' => $count,
			'list'  => $data
		];
		return $this->echoJson($assign);
	}

	/**
	 * [detailAction 城市详情]
	 * @return [type] [description]
	 */
	public function detailAction()
	{
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = DicsService::getInfo($raw->id, self::CATE_AREA);
		return $this->echoJson($data);
	}

	/**
	 * [udetailAction 城市特色]
	 * @return [type] [description]
	 */
	public function udetailAction()
	{
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = DicsService::getInfo($raw->id, self::CATE_UNIQUE);
		return $this->echoJson($data);
	}

	/**
	 * [groupAction 分组]
	 * @return [type] [description]
	 */
	public function groupAction()
	{
		$raw = $this->validation(new CitySearchValidation, $this->request->getJsonRawBody());
		$raw->is_group = "-1";
		$data = DicsService::getGroup($raw);

		$assign = [
			'list'  => $data
		];

		return $this->echoJson($assign);
	}

	/**
	 * [regionAction 地区联调]
	 * @param  integer $pid [description]
	 * @return [type]       [description]
	 */
	public function regionAction()
	{
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = DicsService::getGroup($raw, TRUE);
		return $this->echoJson($data);
	}

	/**
	 * [createAction 新增城市]
	 * @return [type] [description]
	 */
	public function createAction()
	{
		$raw = $this->validation(new DicsValidation, $this->request->getJsonRawBody());
		DicsService::saveCity($raw);
		return $this->echoJson('ok');
	}

	/**
	 * [cuniqueAction 新增城市特色]
	 * @return [type] [description]
	 */
	public function addAction()
	{
		$raw = $this->validation(new DicsValidation, $this->request->getJsonRawBody());
		DicsService::saveUnique($raw);
		return $this->echoJson('ok');
	}

	/**
	 * [updateAction 更新城市]
	 * @return [type] [description]
	 */
	public function updateAction()
	{
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$raw = $this->validation(new DicsValidation, $this->request->getJsonRawBody());
		DicsService::saveCity($raw);
		return $this->echoJson('ok');
	}

	/**
	 * [uupdateAction 更新城市特色]
	 * @return [type] [description]
	 */
	public function setAction()
	{
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$raw = $this->validation(new DicsValidation, $this->request->getJsonRawBody());
		DicsService::saveUnique($raw);
		return $this->echoJson('ok');
	}

	/**
	 * [upAction 上架]
	 * @return [type] [description]
	 */
	public function displayAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = DicsService::display($raw->id);
		return $this->echoJson('ok');
	}

	/**
	 * [deleteAction 删除]
	 * @return [type] [description]
	 */
	public function deleteAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = DicsService::delete($raw->id);
		return $this->echoJson('ok');
	}

	/**
	 * [foreverAction 彻底删除]
	 * @return [type] [description]
	 */
	public function foreverAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = DicsService::forever($raw->id);
		return $this->echoJson('ok');
	}
}